function MyPlane(){

    this.lastPlaneX = 0;
    this.lastPlaneY = 0;
    this.PlaneX = 0;
    this.PlaneY = 0;
    this.centerPosX = 0;
    this.centerPosY = 0;
    this.PlaneWidth = 0
    this.PlaneHeight = 0;
    this.visiable = false;
    var PlaneImgArray;
    var ShieldImg;
    var thunderImgs;

    this.MapLeft = 0;
    this.MapTop = 0;
    this.MapRight = 0;
    this.MapBottom = 0;

    this.direction = 0;//0=left   1=normal  2=right

    this.hasShield = false;//是否有保护罩
    this.shieldCount;

    this.hasThunder = false;
    this.thunderCount;

    this.attackType = 0;
    this.blood = 0;

    //宠物
    var animsImgArray;
    var animsPositionArray;

    this.InitPlane = function InitPlane(originPlaneImgArray, originShieldImg, originthunderImgs, PlaneX, PlaneY, PlaneWidth, PlaneHeight, ScreenWidth, ScreenHeight, attackType, blood, originAnimsImgArray) {
        this.PlaneX = PlaneX;
        this.PlaneY = PlaneY;
        this.PlaneWidth = PlaneWidth;
        this.PlaneHeight = PlaneHeight;
        this.centerPosX = this.PlaneX+this.PlaneWidth/2;
        this.centerPosY = this.PlaneY+this.PlaneHeight/2;
        PlaneImgArray = originPlaneImgArray;
        ShieldImg = originShieldImg;
        thunderImgs = originthunderImgs;
        this.MapLeft = 0;
        this.MapTop = 0;
        this.MapRight = ScreenWidth - PlaneWidth;
        this.MapBottom = ScreenHeight - PlaneHeight;

        this.direction = 1;
        this.visiable = true;
        this.attackType = attackType;
        this.blood = blood;

        this.creatShield();

        this.hasThunder = false;

        animsImgArray = originAnimsImgArray;
//        animsPositionArray = new Array();
        switch (animsImgArray.length){
            case 1:
//                animsPositionArray.push(0);
                animsPositionArray = [0];
                break;

            case 2:
//                animsPositionArray.push(0);
//                animsPositionArray.push(12);
                animsPositionArray = [0, 12];
                break;

            case 3:
//                animsPositionArray.push(0);
//                animsPositionArray.push(8);
//                animsPositionArray.push(16);
                animsPositionArray = [0, 8, 16];
                break;

            case 4:
//                animsPositionArray.push(3);
//                animsPositionArray.push(9);
//                animsPositionArray.push(15);
//                animsPositionArray.push(21);
                animsPositionArray = [3, 9, 15, 21];
                break;

            case 5:
//                animsPositionArray.push(0);
//                animsPositionArray.push(5);
//                animsPositionArray.push(10);
//                animsPositionArray.push(14);
//                animsPositionArray.push(19);
                animsPositionArray = [0, 5, 10, 14, 19];
                break;

            case 6:
//                animsPositionArray.push(0);
//                animsPositionArray.push(4);
//                animsPositionArray.push(8);
//                animsPositionArray.push(12);
//                animsPositionArray.push(16);
//                animsPositionArray.push(20);
                animsPositionArray = [0, 4, 8, 12, 16, 20];
                break;
        }
    };

    this.updatePos = function(moveX, moveY){
        this.lastPlaneX = this.PlaneX;
        this.lastPlaneY = this.PlaneY;

        this.PlaneX = this.PlaneX+ moveX;
        this.PlaneY = this.PlaneY+ moveY;
        if(this.PlaneX > this.MapRight){
            this.PlaneX = this.MapRight;
        }
        if(this.PlaneX < this.MapLeft){
            this.PlaneX = this.MapLeft;
        }
        if(this.PlaneY > this.MapBottom){
            this.PlaneY = this.MapBottom;
        }
        if(this.PlaneY < this.MapTop){
            this.PlaneY = this.MapTop;
        }
    }

    this.paint = function(drawCanvas, effect_count){
        if(this.visiable){
            if(this.hasThunder){
                drawCanvas.drawImage(thunderImgs[0+(zhengchu(effect_count,2))%2], this.centerPosX-79, this.PlaneY-5);
            }

            if(this.direction == 0){
                drawCanvas.drawImage(PlaneImgArray[0+(zhengchu(effect_count,2))%2], this.PlaneX, this.PlaneY);
            }
            else if(this.direction == 1){
                drawCanvas.drawImage(PlaneImgArray[2+(zhengchu(effect_count,2))%2], this.PlaneX, this.PlaneY);
            }
            else if(this.direction == 2){
                drawCanvas.drawImage(PlaneImgArray[4+(zhengchu(effect_count,2))%2], this.PlaneX, this.PlaneY);
            }
            if(this.hasShield){
                drawCanvas.globalAlpha = (zhengchu(this.shieldCount,26)+1)/5;
                drawCanvas.drawImage(ShieldImg, this.PlaneX-6, this.PlaneY-8);
                drawCanvas.globalAlpha = 1;
            }

            if(this.hasThunder){
                drawCanvas.drawImage(thunderImgs[2], this.centerPosX-72, this.PlaneY-15);
            }

            //画宠物
            for(var i = 0; i < animsImgArray.length; i++){
//                console.log("animsPositionArray[i]:"+animsPositionArray[i]);
                drawCanvas.drawImage(animsImgArray[i], this.centerPosX+circleRoundXYArray[animsPositionArray[i]][0]-15, this.centerPosY+circleRoundXYArray[animsPositionArray[i]][1]-15);
            }
        }
    }

    this.getAnimRoundPosition = function(index){
        return animsPositionArray[index];
    }

    this.updateCenterPos = function(){
        this.centerPosX = this.PlaneX+this.PlaneWidth/2;
        this.centerPosY = this.PlaneY+this.PlaneHeight/2;
    }

    this.updateAnimRoundPos = function(effect_count){
        if(effect_count%2==0){
            for(var i = 0; i < animsPositionArray.length; i++){
                animsPositionArray[i]++;
                if(animsPositionArray[i] > 23){
                    animsPositionArray[i] = 0;
                }
            }
        }
    }

    this.updateShieldCount = function(){
        if(this.hasShield){
            this.shieldCount--;
            if(this.shieldCount == 0){
                this.hasShield = false;
            }
        }
    }

    this.creatShield = function(){
        this.hasShield = true;
        this.shieldCount = 129;
    }

    this.creatThunder = function(){
        this.hasThunder = true;
        this.thunderCount = 100;
    }

    this.updateThunderCount = function(){
        if(this.hasThunder){
            this.thunderCount--;
            if(this.thunderCount == 0){
                this.hasThunder = false;
                return true;
            }
        }
        return false;
    }

    this.catchTool = function(functionType){
        if(functionType == 0){
            //提升子弹等级
            if(this.attackType<9){
                this.attackType++;
            }
        }
        else if(functionType == 0){
            //提升子弹等级
            if(this.attackType<9){
                this.attackType++;
            }
        }
    }

    this.changePlane = function(originPlaneImgArray, changeX, ScreenWidth){
        PlaneImgArray = originPlaneImgArray;
        this.MapLeft = 0-changeX;
        this.MapRight = ScreenWidth - this.PlaneWidth+changeX;
    }
}